package com.zs.test.mvpdemo.presenter;

import com.zs.test.mvpdemo.LoginListener;
import com.zs.test.mvpdemo.LoginView;
import com.zs.test.mvpdemo.model.LoginModel;
import com.zs.test.mvpdemo.model.LoginModelImpl;

/**
 * Created by zhangshuai on 17/3/14.
 */

public class LoginPresenterImpl implements LoginPresenter ,LoginListener {

    private LoginView loginView;
    private LoginModel loginModel;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginView = loginView;
        this.loginModel = new LoginModelImpl();
    }

    @Override
    public void checkLogin(String user, String psd) {

        if (loginView != null) {
            loginView.showProgress();
        }
        loginModel.login(user,psd,this);

    }

    @Override
    public void clearLogin() {
        if (loginView != null) {
            loginView = null;
        }
    }

    @Override
    public void userNameError() {
        if (loginView != null) {
            loginView.setUserNameError();
            loginView.hideProgress();
        }
    }

    @Override
    public void passWordError() {

        if (loginView != null) {
            loginView.setPassWordError();
            loginView.hideProgress();
        }

    }

    @Override
    public void loginSuccess() {

        if (loginView != null) {
            loginView.toHome();
            loginView.hideProgress();
        }

    }


}
